package com.miao.rglog.listener;

import com.caifeng.log.Log;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;

@Component
public class LogListener {

    @Resource
    private MongoTemplate mongoTemplate;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "log_queue", durable = "true"),
            exchange = @Exchange(value = "common.direct"),
            key = {"log"}))
    public void logWriter(Log log) {
        mongoTemplate.save(log);
    }
}
